﻿@page
@using SXFramWork.Web
@{
    ViewData["Title"] = "任务分组";
    Layout = AdminLayout.Pjax(HttpContext);
}
<div id="container">


    <div class="list-wall">
        <div class="layui-form list-search">

            <button type="button" class="layui-btn layui-btn-sm layui-hide" data-type="reload">
                <i class="layui-icon layui-icon-refresh"></i> 刷新
            </button>

            <button type="button" class="layui-btn layui-btn-normal" data-type="Add">
                <i class="layui-icon layui-icon-add-circle"></i> 添加
            </button>
            <button type="button" class="layui-btn layui-btn-danger" data-type="Delete">
                <i class="layui-icon"></i>
                删除
            </button>

        </div>
        <table class="layui-hide" id="tablelist" lay-filter="tool"></table>


    </div>


    <script>
            layui.use(['table', 'layer', 'jquery', 'tree', 'common'],
                function () {
                    var table = layui.table,
                        layer = layui.layer,
                        $ = layui.jquery,
                        os = layui.common

                    //加载表格数据
                    os.tableRender({
                        elem: '#tablelist',
                        url: "/api/admin/sysjobgroup/list",
                        cols: [
                            [
                                { type: 'checkbox', fixed: 'left' },
                                { field: 'name', title: '名称', sort: true, fixed: 'left' },
                                { field: 'code', title: '编码' },
                                { field: 'createTime', title: '创建时间' },
                                { title: '操作', width: 160, templet: '#tool' }
                            ]
                        ]
                    })

                    var active = {

                        reload: function () {
                            os.tableReload('tablelist',
                                { where: {} }
                            )
                        },

                        Add: function () {
                            os.Open('添加分组', '/admin/sysjobgroup/add', '500px', '250px', function () {
                            });
                        },
                        Delete: function () {
                            var checkStatus = table.checkStatus('tablelist')
                                , data = checkStatus.data;
                            if (data.length === 0) {
                                os.error("请选择要删除的项目~");
                                return;
                            }
                            var str = '';
                            $.each(data, function (i, item) {

                                str += item.id + ",";

                            });
                            
                            layer.confirm('确定要执行批量删除吗？', function (index) {
                                layer.close(index);
                                os.ajax('api/admin/sysjobgroup/delete/', str, function (res) {
                                    if (res.code === 1) {
                                        active.reload();
                                        os.success('成功删除' + res.data+'条数据');
                                    } else {
                                        os.error(res.msg);
                                    }
                                });
                            });

                        }
                    };


                    $('.list-search .layui-btn').on('click', function () {
                        var type = $(this).data('type');
                        active[type] ? active[type].call(this) : '';
                    });
                 
                });
    </script>

</div>